package com.sg.java.apps;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

public class RF {

    public static void main(String[] args) {
        File dir = new File(args[0]);
        String[] ids = args[1].split(",");
        File[] files = dir.listFiles();
        if (files == null) {
            return;
        }
        List<String> result = new ArrayList<>();
        for (File file : files) {
            try (FileReader fr = new FileReader(file);
                 BufferedReader br = new BufferedReader(fr)) {
                String line;
                while ((line = br.readLine()) != null) {
                    for (String id : ids) {
                        if (line.contains(id)) {
                            result.add(line);
                            break;
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        result.forEach(System.out::println);
    }

}
